package com.vegetable.modules.service.stock.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vegetable.modules.entity.stock.CostAllocationRecord;
import com.vegetable.modules.mapper.stock.CostAllocationRecordMapper;
import com.vegetable.modules.service.stock.ICostAllocationRecordService;
import com.vegetable.modules.vo.stock.CostAllocationRecordVO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 成本分摊记录服务实现类
 * </p>
 *
 * @author Qwen
 * @since 2025-10-17
 */
@Service
public class CostAllocationRecordServiceImpl extends ServiceImpl<CostAllocationRecordMapper, CostAllocationRecord> implements ICostAllocationRecordService {
    
    @Override
    public List<CostAllocationRecord> listByOriginalStockId(Long originalStockId) {
        QueryWrapper<CostAllocationRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("original_stock_id", originalStockId);
        queryWrapper.orderByDesc("create_time");
        return this.list(queryWrapper);
    }
    
    @Override
    public List<CostAllocationRecord> listByAllocatedStockId(Long allocatedStockId) {
        QueryWrapper<CostAllocationRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("allocated_stock_id", allocatedStockId);
        queryWrapper.orderByDesc("create_time");
        return this.list(queryWrapper);
    }
    
    @Override
    public List<CostAllocationRecord> listByAllocationBatchNo(String allocationBatchNo) {
        QueryWrapper<CostAllocationRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("allocation_batch_no", allocationBatchNo);
        queryWrapper.orderByDesc("create_time");
        return this.list(queryWrapper);
    }
    
    @Override
    public IPage<CostAllocationRecordVO> pageWithGoodsInfo(IPage<CostAllocationRecordVO> page, Map<String, Object> params) {
        return baseMapper.selectCostAllocationRecordPageWithGoodsInfo(page, params);
    }
}